//
//  LoginFromModel.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/28.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "LoginFromModel.h"

NSString *const kLoginUserID    = @"userid";
NSString *const kLoginNickName  = @"nickname";
NSString *const kLoginMobile    = @"mobile";
NSString *const kLoginSex       = @"sex";
NSString *const kLoginHead_img  = @"head_img";
NSString *const kLgoginIndustry = @"industry";
NSString *const kLoginBirthday  = @"birthday";
NSString *const kLoginLevel     = @"level";
NSString *const kLoginName      = @"name";

@implementation LoginFromModel

@synthesize userid   = _userid;
@synthesize nickname = _nickname;
@synthesize mobile   = _mobile;
@synthesize sex      = _sex;
@synthesize head_img = _head_img;
@synthesize industry = _industry;
@synthesize birthday = _birthday;
@synthesize level    = _level;
@synthesize name     = _name;

+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

// 初始化
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    if (self && [dict isKindOfClass:[NSDictionary class]])
    {
        _userid   = [self checkNilObjectForKey:kLoginUserID        fromDictionary:dict];
        _nickname = [self checkNilObjectForKey:kLoginNickName      fromDictionary:dict];
        _mobile   = [self checkNilObjectForKey:kLoginMobile        fromDictionary:dict];
        _sex      = [self checkNilObjectForKey:kLoginSex           fromDictionary:dict];
        _head_img = [self checkNilObjectForKey:kLoginHead_img      fromDictionary:dict];
        _industry = [self checkNilObjectForKey:kLgoginIndustry     fromDictionary:dict];
        _birthday = [self checkNilObjectForKey:kLoginBirthday      fromDictionary:dict];
        _level    = [self checkNilObjectForKey:kLoginLevel         fromDictionary:dict];
        _name     = [self checkNilObjectForKey:kLoginName          fromDictionary:dict];
    }
    return self;
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:_userid                   forKey:kLoginUserID];
    [mutableDict setValue:_nickname                 forKey:kLoginNickName];
    [mutableDict setValue:_mobile                   forKey:kLoginMobile];
    [mutableDict setValue:_sex                      forKey:kLoginSex];
    [mutableDict setValue:_head_img                 forKey:kLoginHead_img];
    [mutableDict setValue:_industry                 forKey:kLgoginIndustry];
    [mutableDict setValue:_birthday                 forKey:kLoginBirthday];
    [mutableDict setValue:_level                    forKey:kLoginLevel];
    [mutableDict setValue:_name                     forKey:kLoginName];
    
    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (id)checkNilObjectForKey:(id)key fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:key];
    return [object isKindOfClass:[NSNull class]] ? nil : object;
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@",[self dictionaryRepresentation]];
}

@end
